<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>camunda-qa-performance-tests-engine</artifactId>
  <packaging>jar</packaging>
  <name>Camunda Platform - QA Performance Tests Engine</name>

  <parent>
    <groupId>org.camunda.bpm.qa</groupId>
    <artifactId>camunda-qa</artifactId>
    <version>7.20.0-SNAPSHOT</version>
  </parent>

  <properties>
    <test.includes />
    <!-- without a special test profile we don't want to exclude anything, this expressions should never match -->
    <test.excludes>$.</test.excludes>
    <historyLevel>full</historyLevel>
    <jdbcBatchProcessing>true</jdbcBatchProcessing>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>1.9.11</version>
    </dependency>

    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-jdbc</artifactId>
      <version>7.0.33</version>
    </dependency>

    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-juli</artifactId>
      <version>7.0.33</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.uuid</groupId>
      <artifactId>java-uuid-generator</artifactId>
    </dependency>

    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
    </dependency>

  </dependencies>

  <profiles>

    <!-- distro profile skips tests -->
    <profile>
      <id>distro</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <!-- the benchmark performs multiple runs of the same process on multiple threads. -->
    <profile>
      <id>benchmark</id>

      <properties>
        <!-- default values for properties -->
        <numberOfThreads>2</numberOfThreads>
        <numberOfRuns>100</numberOfRuns>
        <testWatchers />
        <processEnginePlugins />
        <watchActivities />
        <test.excludes>query</test.excludes>
      </properties>

      <build>
        <testResources>
          <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
          </testResource>
        </testResources>

        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <runOrder>alphabetical</runOrder>
              <redirectTestOutputToFile>true</redirectTestOutputToFile>
              <argLine>-Xmx1024m</argLine>
              <includes>
                 <include>%regex[.*(${test.includes}).*Test.*.class]</include>
              </includes>
              <excludes>
                <exclude>**/*TestCase.java</exclude>
                <exclude>%regex[.*(${test.excludes}).*Test.*.class]</exclude>
              </excludes>
            </configuration>
          </plugin>

          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.4</version>
            <executions>
              <execution>
                <id>database-test-drop-schema</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <echo message="Generating reports" />
                    <copy todir="${basedir}/target/reports/images" flatten="true">
                      <fileset dir="${basedir}/src/test/resources">
                        <include name="**/*.png" />
                      </fileset>
                    </copy>
                    <java classname="org.camunda.bpm.qa.performance.engine.benchmark.BenchmarkReport" classpathref="maven.test.classpath" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>

        </plugins>

      </build>

    </profile>


    <!-- the benchmark performs multiple runs of the same process on multiple threads. -->
    <profile>
      <id>single-run</id>

      <properties>
        <!-- default values for properties -->
        <numberOfThreads>1</numberOfThreads>
        <numberOfRuns>1</numberOfRuns>
        <testWatchers />
        <processEnginePlugins />
        <watchActivities />
        <test.excludes>query</test.excludes>
      </properties>

      <build>
        <testResources>
          <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
          </testResource>
        </testResources>

        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <redirectTestOutputToFile>true</redirectTestOutputToFile>
              <argLine>-Xmx1024m</argLine>
              <includes>
                 <include>%regex[.*(${test.includes}).*Test.*.class]</include>
              </includes>
              <excludes>
                <exclude>**/*TestCase.java</exclude>
                <exclude>%regex[.*(${test.excludes}).*Test.*.class]</exclude>
              </excludes>
            </configuration>
          </plugin>

          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.4</version>
            <executions>
              <execution>
                <id>database-test-drop-schema</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <echo message="Generating reports" />
                    <copy todir="${basedir}/target/reports/images" flatten="true">
                      <fileset dir="${basedir}/src/test/resources">
                        <include name="**/*.png" />
                      </fileset>
                    </copy>
                    <java classname="org.camunda.bpm.qa.performance.engine.benchmark.BenchmarkReport" classpathref="maven.test.classpath" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>

        </plugins>

      </build>

    </profile>

    <!-- Allows to log the process engine's interaction with the database -->
    <profile>
      <id>sql-statementlog</id>

      <properties>
        <numberOfThreads>1</numberOfThreads>
        <numberOfRuns>1</numberOfRuns>
        <testWatchers>org.camunda.bpm.qa.performance.engine.sqlstatementlog.StatementLogPerfTestWatcher</testWatchers>
        <processEnginePlugins>org.camunda.bpm.qa.performance.engine.sqlstatementlog.StatementLogProcessEnginePlugin</processEnginePlugins>
        <watchActivities />
        <test.excludes>query</test.excludes>
      </properties>

      <build>
        <testResources>
          <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
          </testResource>
        </testResources>

        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <redirectTestOutputToFile>true</redirectTestOutputToFile>
              <argLine>-Xmx1024m</argLine>
              <includes>
                 <include>%regex[.*(${test.includes}).*Test.*.class]</include>
              </includes>
              <excludes>
                <exclude>**/*TestCase.java</exclude>
                <exclude>%regex[.*(${test.excludes}).*Test.*.class]</exclude>
              </excludes>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.4</version>
            <executions>
              <execution>
                <id>database-test-drop-schema</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <echo message="Generating reports in ${basedir}/target/reports/" />
                    <copy todir="${basedir}/target/reports/images" flatten="true">
                      <fileset dir="${basedir}/src/test/resources">
                        <include name="**/*.png" />
                      </fileset>
                    </copy>
                    <java classname="org.camunda.bpm.qa.performance.engine.sqlstatementlog.SqlStatementLogReport" classpathref="maven.test.classpath" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>

      </build>

    </profile>

    <profile>
      <id>generate-load</id>

      <properties>
        <loadGenerator.numberOfIterations>10000</loadGenerator.numberOfIterations>
        <loadGenerator.colorOutput>false</loadGenerator.colorOutput>
        <testWatchers />
        <processEnginePlugins />
        <watchActivities />
        <skip.tests>true</skip.tests>
      </properties>

      <build>
        <testResources>
          <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
          </testResource>
        </testResources>

        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.4</version>
            <executions>
              <execution>
                <id>generate load</id>
                <phase>process-test-classes</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <echo message="Generating load" />
                    <java classname="org.camunda.bpm.qa.performance.engine.query.DefaultLoadGenerator" classpathref="maven.test.classpath" failonerror="true" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skipTests>${skip.tests}</skipTests>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>


    <profile>
      <id>query-perf-test</id>

      <properties>
        <numberOfThreads>1</numberOfThreads>
        <numberOfRuns>1</numberOfRuns>
        <testWatchers>org.camunda.bpm.qa.performance.engine.sqlstatementlog.StatementLogPerfTestWatcher</testWatchers>
        <processEnginePlugins>org.camunda.bpm.qa.performance.engine.sqlstatementlog.StatementLogProcessEnginePlugin</processEnginePlugins>
        <watchActivities />
        <test.includes>query</test.includes>
        <skip.tests>false</skip.tests>
      </properties>

      <build>
        <testResources>
          <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
          </testResource>
        </testResources>

        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <redirectTestOutputToFile>true</redirectTestOutputToFile>
              <argLine>-Xmx1024m</argLine>
              <includes>
                 <include>%regex[.*(${test.includes}).*Test.*.class]</include>
              </includes>
              <excludes>
                <exclude>**/*TestCase.java</exclude>
                <exclude>%regex[.*(${test.excludes}).*Test.*.class]</exclude>
              </excludes>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.4</version>
            <executions>
              <execution>
                <id>database-test-drop-schema</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <echo message="Generating reports in ${basedir}/target/reports/" />
                    <copy todir="${basedir}/target/reports/images" flatten="true">
                      <fileset dir="${basedir}/src/test/resources">
                        <include name="**/*.png" />
                      </fileset>
                    </copy>
                    <java classname="org.camunda.bpm.qa.performance.engine.sqlstatementlog.SqlStatementLogReport" classpathref="maven.test.classpath" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>

      </build>

    </profile>

    <!-- allows to log activity start/end counts -->
    <profile>
      <id>activity-count</id>

      <properties>
        <!-- default values for properties -->
        <numberOfThreads>1</numberOfThreads>
        <numberOfRuns>100</numberOfRuns>
        <testWatchers />
        <processEnginePlugins />
        <watchActivities />
      </properties>

      <build>
        <testResources>
          <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
          </testResource>
        </testResources>

        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <redirectTestOutputToFile>true</redirectTestOutputToFile>
              <argLine>-Xmx1024m</argLine>
              <includes>
                 <include>%regex[.*(${test.includes}).*Test.*.class]</include>
              </includes>
              <excludes>
                <exclude>**/*TestCase.java</exclude>
                <exclude>%regex[.*(${test.excludes}).*Test.*.class]</exclude>
              </excludes>
            </configuration>
          </plugin>

          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.4</version>
            <executions>
              <execution>
                <id>generate-report</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <echo message="Generating reports" />
                    <copy todir="${basedir}/target/reports/images" flatten="true">
                      <fileset dir="${basedir}/src/test/resources">
                        <include name="**/*.png" />
                      </fileset>
                    </copy>
                    <java classname="org.camunda.bpm.qa.performance.engine.framework.activitylog.ActivityCountReporter" classpathref="maven.test.classpath" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>

        </plugins>

      </build>

    </profile>

    <!-- override h2 profile to use in-mem db -->
    <profile>
      <id>h2</id>
      <properties>
        <database.type>h2</database.type>
        <database.username>sa</database.username>
        <database.password>sa</database.password>
        <database.driver>org.h2.Driver</database.driver>
        <database.datasource.class>org.h2.jdbcx.JdbcDataSource</database.datasource.class>
        <database.url>jdbc:h2:mem:performance-test</database.url>
      </properties>
    </profile>


    <profile>
      <id>history-level-none</id>
      <properties>
        <historyLevel>none</historyLevel>
      </properties>
    </profile>

    <profile>
      <id>history-level-full</id>
      <properties>
        <historyLevel>full</historyLevel>
      </properties>
    </profile>

    <profile>
      <id>cfgJdbcBatchProcessingOff</id>
      <properties>
        <jdbcBatchProcessing>false</jdbcBatchProcessing>
      </properties>
    </profile>

    <!-- test profiles -->
    <profile>
     <id>testBpmn</id>
     <properties>
      <test.includes>bpmn</test.includes>
     </properties>
    </profile>
    <profile>
     <id>testDmn</id>
     <properties>
      <test.includes>dmn</test.includes>
     </properties>
    </profile>

  </profiles>


</project>
